package com.ygy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ygy.entity.Messages;
import com.ygy.mapper.MessagesMapper;
import com.ygy.service.IMessagesService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 留言表 服务实现类
 * </p>
 *
 * @author Ye
 * @since 2024-03-14
 */
@Service
public class MessagesServiceImpl extends ServiceImpl<MessagesMapper, Messages> implements IMessagesService {

    @Autowired
    private MessagesMapper messagesMapper;

    //获取未读消息
    public List<Messages> getUnreadMessagesByReceiver(String username) {
//        System.out.println("进入service");
        return messagesMapper.selectUnreadMessagesByReceiver(username);
    }

    //获取全部消息
    @Override
    public List<Messages> listAllByUserId(Integer userId) {
        // 查询该用户作为发送者或接收者的所有消息
        return baseMapper.selectList(new QueryWrapper<Messages>()
                .eq("sender_id", userId)
                .or()
                .eq("receiver_id", userId));
    }
}
